﻿/*****************************************介绍*****************************************
 * 作者：User
 * 创建时间：2025-09-12 16:19:25
 * 功能：界面【PausePanel】的View
        1、负责收集所有控件
**************************************************************************************/

using Game.Framework;
using Game.UI.GamePanel;

namespace Game.UI.PausePanel
{
    public class PausePanelView : PopupPanel
    {
        public const string PANEL_KEY = "Game_UI_PausePanel_PausePanel_Key";
        private GamePanelView m_GameView;

        protected override void RegistAny()
        {
            PanelManager.Instance.RegistPanel(PANEL_KEY, this);
            EventCenter.Instance.AddEventListen<EAdType, ETriggerAdType>(GameEventName.ON_SHOW_SUCCESS_AD, OnShowSuccessAd);
        }

        protected override void UnregistAny()
        {
            PanelManager.Instance.UnregistPanel(PANEL_KEY);
            EventCenter.Instance.RemoveEventListen<EAdType, ETriggerAdType>(GameEventName.ON_SHOW_SUCCESS_AD, OnShowSuccessAd);
        }

        private void OnShowSuccessAd(EAdType adType, ETriggerAdType triggerType)
        {
            if (adType == EAdType.RewardedVideo && triggerType == ETriggerAdType.RestartLevel)
            {
                m_GameView.Restart();
                UIUtility.HidePanel(PANEL_KEY);
            }
        }

        public override void Init(object data)
        {
            m_GameView = data as GamePanelView;
        }

        protected override void ClickBtnHandle(string name)
        {
            switch (name)
            {
                case PausePanelNotifications.CloseBtn_CTRL:
                case PausePanelNotifications.BackLobbyBtn_CTRL:
                    if (UIUtility.GetPanelState(HallPanel.HallPanelView.PANEL_KEY) != PanelState.Show)
                        UIUtility.DisplayPanel(HallPanel.HallPanelView.PANEL_KEY, "UI/HallPanel/Prefabs/HallPanel");
                    UIUtility.HidePanel(GamePanelView.PANEL_KEY);
                    UIUtility.HidePanel(PANEL_KEY);
                    break;
                case PausePanelNotifications.ContinueBtn_CTRL:
                    m_GameView.ResumeGame();
                    UIUtility.HidePanel(PANEL_KEY);
                    break;
                case PausePanelNotifications.RestartBtn_CTRL:
                    NativeInteraction.Instance.ShowRewardAd(ETriggerAdType.RestartLevel);
                    break;
            }
        }
    }
}